{
  Доступные внутренние элементы

 TInlConfig - Интерфейс к основным модулям конфигурации

 8 основных модулей
  - журнал
  - исполнительная система
  - решатель
  - управление пользователями и правами
  - консоль
  - библиотека
  - база проекта
  - версионность данных

   версия 0.1 март 2011 prodg@ya.ru D.Kondakov
}
unit IIntgrlWrkspc;

{$mode objfpc}{$H+}

interface

{$i calcconfig.inc}

uses
  Classes, SysUtils, IIntgrlTypes, IIntgrlBaseDefs, IIntgrlBaseCnfg,
  LogSystm, ExctnSystm, SolvingSystm, DataMngrSystm, DataHistSystm,
  RefrncDtaSystm, UsersMngrSystm, CommandConsole;

type

  { TInlWorkspace }

  TInlWorkspace = class(TinlConfiguration)
    constructor Create;
    destructor Destroy; override;
  private
    {$ifdef iiMultiUser}faccnt,{$endif}
    {$ifdef iiHistory}fhist,{$endif}
    flog, fexec, fsolv, fcons, fdb, flib: TinlLogicType; // Разрешен ли модуль
    pLOG: TSystmLog;   // Ссылка на модуль журналирования
    pEXEC: TexcSystem;
    pSOLV: TSolvSystem;
    pCONS: TCmdConsole;
    pDB: TProjectDB;
    pLIB: TReferenceDB;
    {$ifdef iiMultiUser}pACCNT: TUsersMngr;{$endif}
    {$ifdef iiHistory}pHIST: TPrjDataHistory;{$endif}
  protected
    function postError(s: TinlStringType): TinlLogicType; override;
    function postWarng(s: TinlStringType): TinlLogicType; override;
    function postHint(s: TinlStringType): TinlLogicType; override;
    function postInfo(s: TinlStringType): TinlLogicType; override;
    {$ifdef iiDebugLog}
    function postDebug(s: TinlStringType): TinlLogicType; override;
    {$endif}
  public
    property LOGon: TinlLogicType read flog default true;
    property EXECon: TinlLogicType read fexec default true;
    property SOLVon: TinlLogicType read fsolv default true;
    property CONSon: TinlLogicType read fcons default true;
    property DBon: TinlLogicType read fdb default true;
    property LIBon: TinlLogicType read flib default true;
    property modLOG: TSystmLog read pLOG default nil;
    property modEXEC: TexcSystem read pEXEC default nil;
    property modSOLV: TSolvSystem read pSOLV default nil;
    property modCONS: TCmdConsole read pCONS default nil;
    property modDB: TProjectDB read pDB default nil;
    property modLIB: TReferenceDB read pLIB default nil;

    {$ifdef iiHistory}
    property HISTon: TinlLogicType read fhist default true;
    property modHIST: TPrjDataHistory read pHIST default nil;
    {$endif}

    {$ifdef iiMultiUser}
    property ACCNTon: TinlLogicType read faccnt default true;
    property modACCNT: TUsersMngr read pACCNT default nil;
    {$endif}

  end;

implementation

{ TInlWorkspace }

constructor TInlWorkspace.Create;
begin
  flog := false;
  pLOG := nil;
  inherited;
  if GetLogicParam('MOD_LOG_ON' ,true) then try
    pLOG := TSystmLog.Create(Self);
    pLOG.AddDefParams(CfgParams);
  finally
    flog := assigned(pLOG);
  end;

  fexec := GetLogicParam('MOD_EXEC_ON' ,true);
  if fexec then pEXEC := TexcSystem.Create(Self) else pEXEC := nil;
  fsolv := GetLogicParam('MOD_SOLV_ON' ,true);
  if fsolv then pSOLV := TSolvSystem.Create(Self) else pSOLV := nil;
  {$ifdef iiMultiUser}
  faccnt := GetLogicParam('MOD_ACCNT_ON' ,true);
  if faccnt then pACCNT := TUsersMngr.Create(Self) else pACCNT := nil;
  {$endif}
  fdb := GetLogicParam('MOD_DB_ON' ,true);
  if fdb then pDB := TProjectDB.Create(Self) else pDB := nil;
  flib := GetLogicParam('MOD_LIB_ON' ,true);
  if flib then pLIB := TReferenceDB.Create(Self) else pLIB := nil;
  {$ifdef iiHistory}
  fhist := GetLogicParam('MOD_HIST_ON' ,true);
  if fhist then pHIST := TPrjDataHistory.Create(Self) else pHIST := nil;
  {$endif}
  fcons := GetLogicParam('MOD_CONS_ON' ,true);
  if fcons then pCONS := TCmdConsole.Create(Self) else pCONS := nil;

end;

destructor TInlWorkspace.Destroy;
begin
  if fCONS and assigned(pCONS) then FreeAndNil(pCONS);
  if fSOLV and assigned(pSOLV) then FreeAndNil(pSOLV);
  if fEXEC and assigned(pEXEC) then FreeAndNil(pEXEC);
  if fLIB and assigned(pLIB) then FreeAndNil(pLIB);
  if fDB and assigned(pDB) then FreeAndNil(pDB);
  {$ifdef iiHistory}
  if fHIST and assigned(pHIST) then FreeAndNil(pHIST);
  {$endif}
  {$ifdef iiMultiUser}
  if fACCNT and assigned(pACCNT) then FreeAndNil(pACCNT);
  {$endif}
  if fLOG and assigned(pLOG) then begin
    fLOG := false;
    FreeAndNil(pLOG);
  end;
  doInfo(logEndModules);
  inherited;
end;

function TInlWorkspace.postError(s: TinlStringType): TinlLogicType;
begin
  result := inherited postError(s);
  result := (LOGon and (modLOG.logMsg(msgError, s)<>msgNot)) or result;
end;

function TInlWorkspace.postWarng(s: TinlStringType): TinlLogicType;
begin
  result:=inherited postWarng(s);
  result := (LOGon and (modLOG.logMsg(msgWrng, s)<>msgNot)) or result;
end;

function TInlWorkspace.postHint(s: TinlStringType): TinlLogicType;
begin
  result:=inherited postHint(s);
  result := (LOGon and (modLOG.logMsg(msgHint, s)<>msgNot)) or result;
end;

function TInlWorkspace.postInfo(s: TinlStringType): TinlLogicType;
begin
  result:=inherited postInfo(s);
  result := (LOGon and (modLOG.logMsg(msgInfo, s)<>msgNot)) or result;
end;

function TInlWorkspace.postDebug(s: TinlStringType): TinlLogicType;
begin
  result:=inherited postDebug(s);
  result := (LOGon and (modLOG.logMsg(msgDebug, s)<>msgNot)) or result;
end;

end.

